﻿<template>
<a-card :bordered="false" style="margin-bottom: 10px">
  <a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
    <a-row :gutter="24">
    <a-col :span="6">
      <a-form-item name="name" label="学校名称">
        <a-input v-model:value="searchFormState.name" placeholder="请输入学校名称"></a-input>
      </a-form-item>
    </a-col>
    <a-col :span="6">
      <a-button type="primary" @click="table.refresh(true)">
        <template #icon><SearchOutlined /></template>查询</a-button>
      <a-button class="buttom-left" @click="() => searchFormRef.resetFields()">
        <template #icon><redo-outlined /></template>重置</a-button>
    </a-col>
    </a-row>
  </a-form>
</a-card>
<a-card :bordered="false">
  <s-table
    ref="table"
    :columns="columns"
    :data="loadData"
    :alert="options.alert.show"
    :scroll="{ x: '1000px' | true }"
    bordered
        :row-key="(record) => record.id"
    :row-selection="options.rowSelection"
    :tool-config="toolConfig"
  >
    <template #operator>
      <a-space>
        <a-button type="primary" @click="formRef.onOpen()"  v-if="hasPerm('buSchoolAdd')">
        <template #icon><plus-outlined /></template>新增学校</a-button>
      </a-space>
    </template>
    <template #bodyCell="{ column, record }">
      <template v-if="column.dataIndex === 'logo'">
         <a-image :src="record.logo" style="height: 20px;width: 20px;"/>
      </template>
      <template v-if="column.dataIndex === 'action'">
        <a-space>
          <a @click="formRef.onOpen(record)" v-if="hasPerm('buSchoolEdit')" >编辑</a>
          <a-divider type="vertical"  v-if="hasPerm(['buSchoolEdit', 'buSchoolDelete'], 'and')" />
          <a-popconfirm title="确定要删除吗？" @confirm="deleteBuSchool(record)">
            <a-button type="link" danger size="small"  v-if="hasPerm('buSchoolDelete')">删除</a-button>
          </a-popconfirm>
      </a-space>
      </template>
    </template>
  </s-table>
</a-card>
<Form ref="formRef" @successful="table.refresh(true)" />
</template>

<script setup name="school">
  import { message, Empty } from 'ant-design-vue'
  import Form from './form.vue'
  import buSchoolApi from '@/api/biz/buSchoolApi'
  
  let searchFormState = reactive({}) //查询表单状态
  const searchFormRef = ref() //查询表单
  // 查询区域显示更多控制
  const advanced = ref(false)
  const toggleAdvanced = () => {
      advanced.value = !advanced.value
  }
  const formRef = ref()//新增/编辑表单页
  


  //表格配置
  const table = ref() //表格
  let selectedRowKeys = ref([]) //选中项
  const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false } //表格工具配置
  const columns = [
  {
        title: '学校id',
        width: 100,
        dataIndex: 'id'
      },
      {
        title: '学校logo',
        width: 100,
        dataIndex: 'logo'
      },
      {
        title: '学校名称',
        width: 100,
        dataIndex: 'name'
      },
  ]
  if (hasPerm(['buSchoolEdit', 'buSchoolDelete'])) {
	  columns.push({
		  title: '操作',
	  	  dataIndex: 'action',
	      align: 'center',
          fixed: 'right',
		  width: '130px'
	  })
  }
  
  // 列表选择配置
  const options = reactive({
		alert: {
			show: true, //显示选择多少个
			clear: () => {
				selectedRowKeys = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}) 
  
  
  
  // 表格查询 返回 Promise 对象
  const loadData = (parameter) => {
      const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
      return buSchoolApi.schoolPage(Object.assign(parameter, searchFormParam)).then((data) => {
         return data })
    }
    
  // 删除
  const deleteBuSchool = (record) => {
      let params = [
          {
            id: record.id ,
          }
      ]
      buSchoolApi.schoolDelete(params).then(() => {
        table.value.refresh(true)
      })
  }
   
  
  
  


</script>


<style scoped>
    .buttom-left {
      margin-left: 8px;
    }
</style>

